// Copyright (c) 2025, 大连理工大学 (Dalian University of Technology)
//
// Licensed under the Mulan PSL v2.
// You can use this file according to the terms and conditions of the Mulan PSL v2.
// You may obtain a copy of the License at
//
//     http://license.coscl.org.cn/MulanPSL2
//
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
// EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. SEE THE MULAN PSL v2
// FOR MORE DETAILS.

/*
 * @Author: qiulin_JXGM ql1746365080@gmail.com
 * @Date: 2024-10-22 16:27:56
 * @LastEditors: qiulin ql1746365080@gmail.com
 * @LastEditTime: 2024-12-12 15:11:57
 * @FilePath: \SGFEM\Import\BDFImport\test\Load\PLOAD2ParserTest.cpp
 */

#include "Import/BDFImport/BulkData/Load/PLOAD2Parser.h"

#include "gtest/gtest.h"

#include "DataStructure/Common/Constant.h"
#include "DataStructure/Input/Load/PLOAD2Data.h"

#include "DBManager/DBServiceFactory.h"
#include "DBManager/IService/Input/Load/IPLOAD2Service.h"

#include "Import/BDFImport/BDFParserBase.h"
using namespace SG::DBManager;
using namespace SG::Import;

using SG::DataStructure::Common::TOLERANCE;
using namespace SG::DataStructure::FEM;
extern std::shared_ptr<DBServiceFactory> DB_SERVICEFACTORY;
extern std::vector<std::string>          dividedEntryInfo;

class PLOAD2ParserTest : public ::testing::Test
{
  public:
    static void SetUpTestSuite ()
    {
        DB_SERVICEFACTORY->ClearDatabase ();
    }
};

TEST_F (PLOAD2ParserTest, ParseEntry1)
{
    std::vector<std::string> Entry = { "PLOAD2         1     0.5       1       2       3       4       5       6+000008A",
                                       "+000008A       7       8" };
    BDF::divideBulkEntry (Entry, dividedEntryInfo);
    SG::Import::BDF::BULKDATA::ParsePLOAD2 (DB_SERVICEFACTORY, dividedEntryInfo);
    std::vector<SG::DataStructure::FEM::PLOAD2Data> Ploads;

    SG::DataStructure::FEM::PLOAD2Data data;

    DB_SERVICEFACTORY->get<IPLOAD2Service> ()->FindBySId (1, Ploads);

    data = Ploads[0];

    ASSERT_TRUE (data.m_sId == 1);
    ASSERT_TRUE (data.m_eId == 1);
    ASSERT_TRUE (Ploads.size () == 8);

    ASSERT_NEAR (data.m_P, 0.5, TOLERANCE);
}

TEST_F (PLOAD2ParserTest, ParseEntry2)
{
    std::vector<std::string> Entry = { "PLOAD2         2     0.5       1    THRU       8" };
    BDF::divideBulkEntry (Entry, dividedEntryInfo);
    SG::Import::BDF::BULKDATA::ParsePLOAD2 (DB_SERVICEFACTORY, dividedEntryInfo);
    std::vector<SG::DataStructure::FEM::PLOAD2Data> Ploads;

    SG::DataStructure::FEM::PLOAD2Data data;

    DB_SERVICEFACTORY->get<IPLOAD2Service> ()->FindBySId (2, Ploads);

    data = Ploads[0];

    ASSERT_TRUE (data.m_sId == 2);
    ASSERT_TRUE (data.m_eId == 1);
    ASSERT_TRUE (Ploads.size () == 8);

    ASSERT_NEAR (data.m_P, 0.5, TOLERANCE);
}